package com.burst.reptile.framework.web.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/**
 * layui 返回结果封装
 */
@AllArgsConstructor
@Builder
@Data
public class LayuiResult<T> {
	
	public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";

	public static final String DEFAULT_ERROR_MESSAGE = "服务器异常";

	public static final Integer DEFAULT_SUCCESS_CODE = 200;

	public static final Integer DEFAULT_ERROR_CODE = 500;

	private int code;

	private String msg;

	private long count;

	private T data;
	
	private boolean hasNext;

	/**
	 * 成功时候的调用
	 */
	public static <T> LayuiResult<T> success(long count, T data) {
		return new LayuiResult<T>(count, DEFAULT_SUCCESS_MESSAGE, data);
	}

	/**
	 * 成功时候的调用
	 */
	public static <T> LayuiResult<T> success(T data) {
		return new LayuiResult<T>(DEFAULT_SUCCESS_MESSAGE, data);
	}
	
	/**
	 * 成功时候的调用
	 */
	public static <T> LayuiResult<T> success(boolean hasNext, long count, T data) {
		return new LayuiResult<T>(hasNext, count, DEFAULT_SUCCESS_MESSAGE, data);
	}

	/**
	 * 失败时候的调用
	 */
	public static <T> LayuiResult<T> error(Integer code, String msg) {
		return new LayuiResult<T>(code, msg);
	}

	public static <T> LayuiResult<T> error() {
		return new LayuiResult<T>(DEFAULT_ERROR_CODE, DEFAULT_ERROR_MESSAGE);
	}

	private LayuiResult(String msg, T data) {
		this.msg = msg;
		this.data = data;
	}

	private LayuiResult(long count, String msg, T data) {
		this.count = count;
		this.msg = msg;
		this.data = data;
	}
	
	private LayuiResult(boolean hasNext, long count,  String msg, T data) {
		this.hasNext = hasNext;
		this.count = count;
		this.msg = msg;
		this.data = data;
	}

	public LayuiResult(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}


}
